package com.angus.modules.content.controller.work;

import com.angus.common.core.web.controller.BaseController;
import com.angus.common.core.web.domain.AjaxResult;
import com.angus.common.security.utils.SecurityUtils;
import com.angus.modules.content.dto.MyCollectionDto;
import com.angus.modules.content.service.IMyCollectionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liyanan
 */
@RestController
@RequestMapping("/front/collection")
public class MyCollectionController extends BaseController {

    @Resource
    private IMyCollectionService myCollectionService;

    /**
     * 加入收藏
     */
    @PostMapping("/add")
    public AjaxResult addCollection(@RequestBody MyCollectionDto dto) {
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(myCollectionService.addCollection(dto,userId));
    }

    /**
     * 取消收藏
     */
    @DeleteMapping("/cancel")
    public AjaxResult cancelCollection(@RequestBody MyCollectionDto dto) {
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(myCollectionService.cancelCollection(dto,userId));
    }

    /**
     * 批量取消收藏
     */
     @DeleteMapping("/cancel/batch")
    public AjaxResult cancelCollectionBatch(@RequestBody List<Long> ids) {
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(myCollectionService.cancelCollectionBatch(ids,userId));
    }

    /**
     * 获取收藏信息
     * @return
     */
    @GetMapping("/query")
    public AjaxResult queryCollection(@RequestParam String courseCode, @RequestParam Long groupId,@RequestParam String unitNum, @RequestParam String groupFlag){
        Long userId = SecurityUtils.getUserId();
        MyCollectionDto dto = new MyCollectionDto();
        dto.setCourseCode(courseCode);
        dto.setGroupId(groupId);
        dto.setUnitNum(unitNum);
        dto.setGroupFlag(groupFlag);
        return AjaxResult.success(myCollectionService.queryCollection(dto,userId));
    }

    /**
     * 我的收藏数据（含中英词汇）
     */
    @GetMapping("/list")
    public AjaxResult list() {
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(myCollectionService.getMyCollectionList(userId));
    }

}
